<?php

if (!defined('_PAGE_'))
    include _FLEP_LIB_DIR_.'/page.inc';

$css = array('main.css', 'estudiante.css');
$javascript = array('common.js', 'estudiante.js');

$structure = flep_page_init('docente');

function include_page($structure){
?>
    <h3><a href="main.php?page=docente">Docentes</a></h3>
    <br>
    <div class="menu">
        <a href="?page=add_docente">Agregar</a>&nbsp;|&nbsp;
        <a href="?page=curso">Cursos</a>&nbsp;|&nbsp;
        <?php flep_page_search($structure); ?>
    </div>
    <br>
    <table>
    <tr>
    <td>
      <b><?php
        flep_page_message();
        flep_page_navigation($structure);
    ?></b>
    </td><td>&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2">
        <br>
    <table class="list">
        <thead><tr><th>N&deg;</th><?php
            foreach($structure['fields'] as &$field){
                printf('<th>%s</th>', $field['title']);
            }
            unset($field);
        ?>
        <th></th>
        <th></th>
        <th></th>
        </tr></thead>
        <tfoot>
            <tr><th colspan="<?php echo count($structure['fields']) + 4;?>"></th></tr>
        </tfoot>
        <tbody><?php
            if(flep_search_all($structure)){
                for($i = 0; $i < count($structure['data']); $i++){
                    printf('<tr><td>%s</td>', $i+1);
                    foreach($structure['fields'] as $id => &$field){
                        switch ($field['type']) {
                            case 'text':
                            case 'number':
                                printf('<td title="%s">%s</td>', $field['title'], $structure['data'][$i][$id]);
                                break;
                            case 'list':
                                printf('<td title="%s">%s</td>', $field['title'], $structure['data'][$i][substr($id, 0, strlen($id) - 3)]);
                                break;
                            case 'bool':
                                printf('<td title="%s"><img src="img/%s.png" title="%s"></td>', $field['title'], ($structure['data'][$i][$id]?'ok':'close'), ($structure['data'][$i][$id]?'Activo':'Inactivo'));
                                break;
                            default:
                                break;
                        }
                    }
                    printf('<td style="text-align:center;padding:0px;"><a href="?page=detalle_docente&id=%1$s"><img src="img/details.png" title="Detalles"></a></td><td style="text-align:center;padding:0px;"><a href="?page=add_docente&id=%1$s"><img src="img/edit.png" title="Editar"></a></td><td style="text-align:center;padding:0px;"><a href="delete.php?type=docente&id=%1$s"><img src="img/delete.png" title="Eliminar"></a></td></tr>', flep_encode($structure['data'][$i]['id']));
                }
            }else{
                printf('<tr><td colspan="%s">No hay Docentes - Haga click en Agregar.</td></tr>', count($structure['fields'])+4);
            }
        ?></tbody>
    </table>
            </td></tr>
  </table>
<?php
}

function include_menu(){
    include_main_menu();
}

?>
